package bruce.dai;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class IntentWithData extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent i = new Intent(IntentWithData.this, SecondActivity.class);
				Bundle b = new Bundle();
				String name = ((EditText)findViewById(R.id.editText1)).getText().toString();
				
				saveNameWithSharedPref(name);
				b.putString("name", name);
				i.putExtras(b);
				startActivity(i);
			}

			private void saveNameWithSharedPref(String name) {
				SharedPreferences sp =getSharedPreferences("bruce",0);
				sp.edit().putString("name",name).commit();
				
			}
		});
    }
}